﻿using System;
using System.Collections.Generic;
using System.Linq;
using DeepZoomPivotConstructor.PivotLib;
using HtmlAgilityPack;
using PivotPhysicsPlotsGenerator.Utilities;

namespace PivotPhysicsPlotsGenerator.ATLAS
{
    /// <summary>
    /// Scan a table for nodes in that table.
    /// </summary>
    class ParseTableForImages
    {
        public ParseTableForImages(Uri baseUri)
        {
            BaseUri = baseUri;
        }

        /// <summary>
        /// Looks at a single table to gather out the images.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public IEnumerable<PivotImage> Process(HtmlNode node)
        {
            if (node.Name != "table")
            {
                return Enumerable.Empty<PivotImage>();
            }

            var p = new ParseTableRowForImages(BaseUri);
            var images = node.ScanSubNodes("tr").SelectMany(subnode => p.Process(subnode));
            return images;
        }


        private Uri BaseUri { get; set; }
    }
}
